home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / plauger / isxdbl.c < prev    next >
C/C++ Source or Header  |  1994-06-09  |  586b  |  28 lines

  1. -------------------------- Listing 10: double extractor ---------
  2.  
  3. // isxdouble -- istream::operator>>(double&)
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include <istream>
  7.  
  8. istream& istream::operator>>(double& d)
  9.     {    // extract a double
  10.     _TRY_IO_BEGIN
  11.     if (!ipfx())
  12.         setstate(failbit);
  13.     else
  14.         {    // gather characters and convert
  15.         char ac[_MAX_EXP_DIG+_MAX_SIG_DIG+16];
  16.         char *ep;
  17.         errno = 0;
  18.         const double x = _Stod(ac, &ep, _Getffld(ac));
  19.         if (ep == ac || errno != 0)
  20.             setstate(failbit);
  21.         else
  22.             d = x;
  23.         }
  24.     isfx();
  25.     _CATCH_IO_END
  26.     return (*this);
  27.     }
  28.